<link rel="stylesheet" href="css/detail.css" type="text/css" />
<script type="text/javascript" src="js/show_ads.js"></script>
<link rel="stylesheet" href="css/checkbox.css" type="text/css" />
<div id="contentCntr">	
				
				
				<div id="detail">
					<table width="100%" border="0" cellspacing="10" cellpadding="0">
					  <tr>
						<td class="title_detail">ชื่อเรื่อง</td>
						<td class="title_detail"><?=$dataList['title']?> </td>
					  </tr>
					  <tr>
						<td width="100px"><b>ประเภทข้อมูล</b></td>
						<td>
							<? echo @$this->db->getone("SELECT title FROM tbknowledgetype WHERE id=".$dataList['knowledgetypeid']);?>
						</td>
					  </tr>
					  <tr>
						<td><b>หน่วยงาน</b></td>
						<td>
							<? echo @$this->db->getone("SELECT title FROM tbsection WHERE id=".$dataList['sectionid']);?>
						</td>
					  </tr>
					  <tr>
						<td><b>ผู้จัดทำ</b></td>
						<td>
							<?php 
								$authors = $this->db->getarray('select tags.tag from tags join tbknowledge_author as ktags on ktags.author_id = tags.id  where ktags.tbknowledge_id = ?', array($dataList['id']));
								foreach($authors as $k => $author) echo ($k > 0) ? ', '.$author['tag'] : $author['tag'];
							?>
						</td>
					  </tr>
					  <tr>
						<td><b>วันที่เผยแพร่</b></td>
						<td><?=DB2Date($dataList['publishdate'])?></td>
					  </tr>
					  <tr>
						<td><b>Tags</b></td>
						<td>	
							<?php 
								$tags = $this->db->getarray('select tags.tag from tags join tbknowledge_tag as ktags on ktags.tag_id = tags.id  where ktags.tbknowledge_id = ?', array($dataList['id']));
								foreach($tags as $k => $tag) echo ($k > 0) ? ', '.$tag['tag'] : $tag['tag'];
							?>
						</td>
					  </tr>
					  <tr>
						<td><b>รายละเอียด</b></td>
						<td>	
							<? echo @$this->db->getone("SELECT detail FROM tbknowledge WHERE id=".$dataList['id']);?>
						</td>
					  </tr>
					<?php 
					  
						$datafiles = $this->knowledgefiles->where('pid='.$dataList['id'])->get();
				     	$run_no=0;
						foreach($datafiles as $items): 
						$run_no++;
							
					?>
					  	
					 
					<table width="100%" border="0" cellspacing="0" cellpadding="20" class="tb_detail">
						  <tr class="tr_detail">
							<td width="14%" class="td_detail" style="padding-left:10px;">ดาวน์โหลด</td>
							<td width="61%" class="td_detail">&nbsp;</td>
							<td width="14%" class="td_detail">&nbsp;</td>
							<td width="11%" class="td_detail">&nbsp;</td>
						  </tr>
						  <tr class="tr_detail_">
							<td class="td_detail_">ลำดับ</td>
							<td>รายละเอียดไฟล์</td>
							<td><div align="center">จำนวนดาวน์โหลด</div></td>
							<td><div align="center">ดาวน์โหลด</div></td>
						  </tr>
						  <tr class="tr_detail_hover">
							<td class="td_2"><?=$run_no ?></td>
							<td><img src="knowledgefiles/<?php echo $items['imagethumbnail']; ?>">
								<br>
								<br>คำอธิบายไฟล์ : <?=$items['filedescription']; ?> <br>
								<? 
								$filename = "knowledgefiles/".$items['filename'];
								$size = filesize("$filename"); 
								
								
								?>
										ขนาดไฟล์ : <?echo number_format($size/1024/1024,2). "Mb"?><br>
										เปิดด้วยโปรแกรม : <? echo @$this->db->getone("SELECT openprogramname FROM tbfiletype WHERE id=".$items['filetypeid']); ?>							
							</td>
							<td><div align="center"><?=$items['downloads'];?></div></td>
							<td>
								<div align="center">
								<a href="detail/suggestion/<?php echo $items['id']?>" target="_blank"><img border="0" align="absmiddle" height="30px" alt="ดาวน์โหลด" title="ดาวน์โหลด" src="images/icon-download.png"></a>
								<!--<a href="detail/counterfiles/<?php echo $items['id']?>"><img border="0" align="absmiddle" height="30px" alt="ดาวน์โหลด" title="ดาวน์โหลด" src="images/icon-download.png"></a>-->
								</div>
							</td>
							
						  </tr>
						  <tr class="tr_detail_">
							<td class="td_detail_"><b>จำนวนคนอ่าน :</b></td>
							<td><? echo $dataList['counter']?> ครั้ง</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						  </tr>
						  
						
						   <? endforeach; ?>
					  </table>
					 <br />
					 <hr />
					 <br />
				
					
					</table>
			  			<br>			
				</div>
				 
				<div id="same_title">
					<div id="same_title2">
				
						<span class="title_samedetail">หัวข้อที่คล้ายกัน ::</span>
						<?php
						//$this->db->debug = true;
						$sql = 'select t.*
						from tbknowledge_tag
						join tbknowledge as t on t.id =  tbknowledge_tag.tbknowledge_id
						left join tbknowledgeapproverequest as ts on ts.pid = t.id
						where tbknowledge_tag.tag_id in (select tag_id from tbknowledge_tag where tbknowledge_id = ?)
						and tbknowledge_tag.tbknowledge_id != ?
						and ((t.privatestatus = 1 and ts.id is not null and curdate() between ts.approve_start_date and ts.approve_end_date and ts.request_by = ?) or t.privatestatus = 2)
						group by tbknowledge_tag.tbknowledge_id';
						$result = $this->db->getarray($sql, array($dataList['id'], $dataList['id'], $this->session->userdata('id'))); 
						foreach($result as $item):
						?>
								<div class="line4"></div><br>
								<a href="detail/index/<?=$item['id']?>" class="detail_link"><?php echo $item['title']; ?></a> <br>
								<?php 
								$tags = $this->db->getarray('select tags.tag from tags join tbknowledge_tag as ktags on ktags.tag_id = tags.id  where ktags.tbknowledge_id = ?', array($item['id']));
								foreach($tags as $k => $tag) echo ($k > 0) ? ', '.$tag['tag'] : $tag['tag'];
								?>
								<br><br>
						<?php endforeach; ?>
					</div>
				</div>
			

</div>
		
			